home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 2 / MacMania 2.toast / Art⁄Graphics / Image 1.49 / Macros / Measurement Macros < prev    next >
Encoding:
Text File  |  1993-03-26  |  12.0 KB  |  557 lines  |  [TEXT/ttxt]

  1. macro 'Plot X-Y Coordinates';
  2. {Plots the X-Y Coordinates of the current ROI. The plot will be
  3.  upside down if "Invert Y Coordinates" is checked in Preferences.}
  4. var
  5.   i,w,h,width,height:integer;
  6.   x,y,scale,xmax,ymax:real 
  7. begin
  8.   RequiresVersion(1.48);
  9.   if nCoordinates=0 then begin
  10.     PutMessage('No XY-Coordinates currently available.');
  11.     exit;
  12.   end;
  13.   SaveState;
  14.   InvertY(false);
  15.   xmax:=0;
  16.   ymax:=0;
  17.   for i:=1 to nCoordinates do begin
  18.     x:=xCoordinates[i];
  19.     y:=yCoordinates[i];
  20.     if x>xmax then xmax:=x;
  21.     if y>ymax then ymax:=y;
  22.   end;
  23.   scale:=sqrt((300*300)/(xmax*ymax));
  24.   if (xmax*scale)>500 then scale:=500/xmax;
  25.   if (ymax*scale)>500 then scale:=500/ymax;
  26.   SetForegroundColor(255);
  27.   SetBackgroundColor(0);
  28.   SetNewSize(xmax*scale+20,ymax*scale+20);
  29.   MakeNewWindow('Outline');
  30.   MoveTo(xCoordinates[1]*scale+10,yCoordinates[1]*scale+10);
  31.   for i:=2 to nCoordinates do
  32.     LineTo(xCoordinates[i]*scale+10,yCoordinates[i]*scale+10);
  33.   SetFont('Helvetica');
  34.   SetFontSize(12);
  35.   SetText('No background, Center');
  36.   GetPicSize(width,height);
  37.   MoveTo(width/2,height/3);
  38.   Writeln(nCoordinates:1,' coordinate pairs');
  39.   RestoreState;
  40. end;
  41.  
  42.  
  43. macro 'Particle Analysis Test';
  44. var
  45.   x,y,rows,columns,maxradius,radius:integer;
  46. begin
  47.   SaveState;
  48.   rows:=5; columns:=5;
  49.   maxradius:=rows*columns;
  50.   SetForegroundColor(255);
  51.   SetBackgroundColor(0);
  52.   SetNewSize(columns*maxradius*2+20,rows*maxradius*2+20);
  53.   MakeNewWindow('Objects');
  54.   radius:=1;
  55.   for y:=0 to columns-1 do
  56.     for x:=0 to rows-1 do begin
  57.       MakeOvalRoi(x*maxradius*2+10,y*maxradius*2+10,radius*2,radius*2);
  58.       Fill;
  59.       radius:=radius+1;
  60.     end;
  61.   KillRoi;
  62.   SetParticleSize(1,9999);
  63.   LabelParticles(true);
  64.   OutlineParticles(true);
  65.   SetOptions('Area, Perimeter, Major, Minor');
  66.   AnalyzeParticles;
  67.   SetUser1Label('Perim.d');
  68.   SetUser2Label('Area');
  69.   for radius:=1 to maxradius do begin
  70.     rUser1[radius]:=2*3.14159*radius;
  71.     rUser2[radius]:=3.14159*sqr(radius);
  72.   end;
  73.   ShowResults;
  74.   RestoreState;
  75. end;
  76.  
  77.  
  78. macro 'Count Particles at Random Locations';
  79. var
  80.   n,i,width,height,PicID,nLocations:integer;
  81.   size:real;
  82. begin
  83.   RequiresVersion(1.44);
  84.   nLocations:=10;
  85.   size:=0.25;
  86.   n:=1;
  87.   GetPicSize(width,height);
  88.   PicID:=PicNumber;
  89.   SetUser1Label('Count');
  90.   SetOptions('User1');
  91.   for i:=1 to nLocations do begin
  92.     SelectPic(PicID);
  93.     MakeRoi((1-size)*width*random,(1-size)*height*random,size*width,size*height);
  94.     Duplicate('Temp');;
  95.     SetDensitySlice(255,255);
  96.     AnalyzeParticles;
  97.     Dispose;
  98.     rUser1[i]:=rCount;
  99.   end;
  100.   KillRoi;
  101.   SetCounter(nLocations);
  102.   ShowResults;
  103. end;
  104.  
  105.  
  106. macro 'Make Circle from Line';
  107. var
  108.   x1,x2,y1,y2,top,left,width,height:integer;
  109.   xcenter,ycenter,radius:integer;
  110. begin
  111.   GetLine(x1,y1,x2,y2,width);
  112.   if x1<0 then begin
  113.     PutMessage('This macro requires a line selection.');
  114.     exit;
  115.   end;
  116.   xcenter:=x1+(x2-x1)/2;
  117.   ycenter:=y1+(y2-y1)/2;
  118.   radius:=sqrt(sqr(x2-x1)+sqr(y2-y1))/2;
  119.   MakeOvalROI(xcenter-radius,ycenter-radius,radius*2,radius*2);
  120. end;
  121.  
  122.  
  123. macro 'Display Calibration Table';
  124. {
  125. Stores 0-255(all possible gray values) in the User1 column
  126. and the 256 corresponding calibrated values in the User2 column.
  127. Max Measurements must be set to 256 or greater. Use the Export
  128. command to export the calibration table to a text file. The two
  129. columns will be identical if the image is not calibrated.
  130. }
  131. var
  132.   i:integer;
  133.   v:real;
  134. begin
  135.   RequiresVersion(1.44);
  136.   SetCounter(256);
  137.   SetUser1Label('value');
  138.   SetUser2Label('cvalue');
  139.   for i:=0 to 255 do begin
  140.     rUser1[i+1]:=i;
  141.     rUser2[i+1]:=cvalue(i);
  142.   end;
  143.   ShowResults;
  144. end;
  145.  
  146.  
  147. macro 'Measure and draw line [L]';
  148. var
  149.   x1,x2,y1,y2,width:integer;
  150. begin
  151.   GetLine(x1,y1,x2,y2,width);
  152.   if x1<0 then begin
  153.     PutMessage('This macro requires a straight line selection.');
  154.     exit;
  155.   end;
  156.   Measure;
  157.   Fill;
  158.   KillRoi;
  159. end;
  160.  
  161.  
  162. macro 'Measure All';
  163. {Measures all currently open images using the current selection. There is}
  164. {an implied "Select All" if the active image doesn't have a selection.}
  165. var
  166.   i,left,top,width,height:integer;
  167. begin
  168.   ResetCounter;
  169.   for i:=1 to nPics do begin
  170.     SelectPic(i);
  171.     RestoreROI;
  172.     Measure;
  173.   end;
  174. end;
  175.  
  176.  
  177. macro 'Measure All from Disk';
  178. {
  179. Reads from disk and measures a set of images too large to simultaneously
  180. fit in memory. The image names names must be in the form '01', '02', etc.
  181. Before starting, open and outline the first image('01').
  182. }
  183. var
  184.   i,width,height:integer;
  185. begin
  186.   GetPicSize(width,height);
  187.   if width=0 then begin
  188.     PutMessage('Before running this macro, open and outline the first image("01") in the series.');
  189.     exit;
  190.   end;
  191.   ResetCounters;
  192.   Measure;
  193.   close;
  194.   for i:=2 to 1000 do begin
  195.     open(i:2);
  196.     RestoreROI;
  197.     Measure;
  198.     close;
  199.   end;
  200. end;
  201.  
  202.  
  203. macro 'Paste Results [P]'
  204. {Use the Measure command, the ruler tool, or the pointing tool to}
  205. {make up to about 10 measurements, then use this macro to paste}
  206. {the results into the upper left corner of the window.}
  207. begin
  208.   SetFont('Monaco');
  209.   SetFontSize(9);
  210.   SetText('Plain; Align Left');
  211.   SetOption; {Copy headings}
  212.   CopyResults;
  213.   MakeRoi(-10,0,250,150);
  214.   Paste;
  215.   KillRoi;
  216.   ResetCounter;
  217. end;
  218.  
  219.  
  220. macro 'Measure Redirected and Label'
  221. begin
  222.   Redirect(true);
  223.   Measure;
  224.   Redirect(false);
  225.   MarkSelection;
  226.   RestoreRoi;
  227. end;
  228.  
  229.  
  230. macro 'Reset Measurement Options';
  231. {Resets the Options dialog box in the Analyze menu to the default settings.}
  232. begin
  233.   RequiresVersion(1.44);
  234.   SetOptions('Area; Mean');
  235.   Redirect(false);
  236.   LabelParticles(true);
  237.   OutlineParticles(false);
  238.   IgnoreParticlesTouchingEdge(false);
  239.   IncludeInteriorHoles(false);
  240.   WandAutoMeasure(false);
  241.   AdjustAreas(false);
  242.   SetParticleSize(1,999999);
  243.   SetPrecision(2);
  244. end;
  245.  
  246.  
  247. macro 'Set Threshold';
  248. var
  249.   lower,upper:integer;
  250. begin
  251.   lower:=GetNumber('Lower:',1);
  252.   upper:=GetNumber('Upper:',254);
  253.   SetDensitySlice(lower,upper);
  254. end;
  255.  
  256.  
  257. macro 'Measure Accumulated Perimeter[A]';
  258. {
  259. Measures perimeter and computes accumulated perimeter,
  260. storing it in the User1 column.
  261. }
  262. var
  263.   i:integer;
  264.   Total:real;
  265. begin
  266.   MeasurePerimeter(true);
  267.   SetOptions('Area; Mean; Perimeter; User1');
  268.   SetUser1Label('Total');
  269.   Measure;
  270.   Total:=0;
  271.   for i:=1 to rCount do Total:=Total+rLength[i];
  272.   rUser1[rCount]:=Total;
  273.   UpdateResults;
  274. end;
  275.  
  276.  
  277. macro 'Count Black and White Pixels [B]';
  278. {
  279. Counts the number of black and white pixels in the current
  280. selection and stores the counts in the User1 and User2 columns.
  281. }
  282. begin
  283.   RequiresVersion(1.44);
  284.   SetUser1Label('Black');
  285.   SetUser2Label('White');
  286.   Measure;
  287.   rUser1[rCount]:=histogram[255];
  288.   rUser2[rCount]:=histogram[0];
  289.   UpdateResults;
  290. end;
  291.  
  292.  
  293. macro 'Compute Percent Black and White';
  294. var
  295.   nPixels,mean,mode,min,max:real;
  296. begin
  297.   RequiresVersion(1.44);
  298.   SetUser1Label('Black');
  299.   SetUser2Label('White');
  300.   Measure;
  301.   GetResults(nPixels,mean,mode,min,max);
  302.   rUser1[rCount]:=histogram[255]/nPixels;
  303.   rUser2[rCount]:=histogram[0]/nPixels;
  304.   UpdateResults;
  305. end;
  306.  
  307.  
  308. macro 'Compute Average and Total Area [T]';
  309. {
  310. Computes average and accumulated area and stores 
  311. the them in the Major and Minor Axis columns.
  312. }
  313. var
  314.   i:integer;
  315.   sum:real;
  316. begin
  317.   RequiresVersion(1.44);
  318.   SetUser1Label('Avg');
  319.   SetUser2Label('Total');
  320.   SetOptions('Area; User1; User2');
  321.   Measure;
  322.   sum:=0;
  323.   for i:=1 to rCount do sum:=sum+rArea[i];
  324.   rUser1[rCount]:=sum/rCount;
  325.   rUser2[rCount]:=sum;
  326.   UpdateResults;
  327. end;
  328.  
  329.  
  330. macro 'Measure Circularity';
  331. begin
  332.   SetUser1Label('Shape');
  333.   Measure;
  334.   rUser1[rCount]:=4*3.14159265*(rArea[rCount]/sqr(rLength[rCount]));
  335.   UpdateResults;
  336. end;
  337.  
  338.  
  339. macro 'Measure Mean * Area';
  340. begin
  341.   SetUser1Label('Mean*Area');
  342.   Measure;
  343.   rUser1[rCount]:=rMean[rCount]*rArea[rCount];
  344.   UpdateResults;
  345. end;
  346.  
  347.  
  348. macro 'Fit  Ellipse and Draw in White';
  349. var
  350.   left,top,width,height:real;
  351. begin
  352.   GetRoi(left,top,width,height);
  353.   if width=0 then begin
  354.     PutMessage('This macro requires a selection.');
  355.     exit;
  356.   end;
  357.   SetOptions('Area; Mean; X-Y Center');
  358.   Measure;
  359.   SetOption; MarkSelection;
  360.   KillRoi;
  361.   SelectAll;
  362.   KillRoi;
  363.  end;
  364.  
  365.  
  366. macro 'Draw XY Center';
  367. var
  368.   left,top,width,height,x,y:real;
  369. begin
  370.   RequiresVersion(1.44);
  371.   GetRoi(left,top,width,height);
  372.   if width=0 then begin
  373.     PutMessage('This macro requires a selection.');
  374.     exit;
  375.   end;
  376.   SaveState; {Invert Y status saved starting with V1.44b21}
  377.   InvertY(false);
  378.   SetForegroundColor(255); {black}
  379.   SetOptions('Area; Mean; X-Y Center'); {XY Center}
  380.   Measure;
  381.   KillRoi;
  382.   x:=rX[rCount];
  383.   y:=rY[rCount];
  384.   MoveTo(x-5,y);
  385.   LineTo(x+5,y);
  386.   MoveTo(x,y-5);
  387.   LineTo(x,y+5);
  388.   RestoreState;
  389. end;
  390.  
  391.  
  392. macro 'Plot Radial Density Profiles [R]';
  393. var
  394.   x1,y1,x2,y2,pi,angle,delta:real;
  395.   LineWidth,i,nLines,radius,PlotWidth,PlotHeight:integer;
  396.   MinPlotWidth,hMargin,vMargin,PlotLeft,PlotTop:integer;
  397.   LeftMargin,RightMargin,TopMargin,BottomMargin:integer;
  398.   ImageWindow,PlotWindow:integer;
  399.   nPixels,mean,mode,min,max:real;
  400. begin
  401.   RequiresVersion(1.45);
  402.   SaveState;
  403.   GetLine(x1,y1,x2,y2,LineWidth)
  404.   if x1<0 then begin
  405.     PutMessage('Please select a point by clicking with the line tool.');
  406.     exit;
  407.   end;
  408.   radius:=20;
  409.   nLines:=8;
  410.   MinPlotWidth:=140;
  411.   pi:=3.14159;
  412.   delta:=2.0*pi/nLines;
  413.   angle:=0.0;
  414.   PlotWidth:=radius;
  415.   if PlotWidth<MinPlotWidth then PlotWidth:=MinPlotWidth;
  416.   PlotHeight:=0.4*PlotWidth;
  417.   SetPlotSize(PlotWidth,PlotHeight);
  418.   MakeOvalRoi(x1-radius,y1-radius,radius*2,radius*2);
  419.   Measure;
  420.   GetResults(nPixels,mean,mode,min,max);
  421.   min:=min-10;
  422.   if min<0 then min:=0;
  423.   max:=max+10;
  424.   if max>255 then max:=255;
  425.   SetPlotScale(cValue(min),cValue(max));
  426.   SetPlotLabels(false);
  427.   hMargin:=5;
  428.   vMargin:=5;
  429.   if Calibrated
  430.     then LeftMargin:=35
  431.     else LeftMargin:=25;
  432.   TopMargin:=10;
  433.   RightMargin:=10;
  434.   BottomMargin:=20;
  435.   PlotLeft:=hMargin-LeftMargin;
  436.   PlotTop:=vMargin-TopMargin;
  437.   SetNewSize(PlotWidth+2*hMargin,PlotHeight*nLines);
  438.   SetForegroundColor(255);
  439.   SetBackgroundColor(0);
  440.   ImageWindow:=PicNumber;
  441.   MakeNewWindow('Plots');
  442.   PlotWindow:=PicNumber;
  443.   SelectPic(ImageWindow);
  444.   for i:=1 TO nLines do begin
  445.     x2:=x1+round(radius*cos(angle));
  446.     y2:=y1+round(radius*sin(angle));
  447.     MakeLineRoi(x1,y1,x2,y2);
  448.     PlotProfile;
  449.     Copy;
  450.     SelectPic(PlotWindow);
  451.     MakeRoi(PlotLeft,PlotTop,PlotWidth+LeftMargin+RightMargin,
  452.           PlotHeight+TopMargin+BottomMargin);
  453.     Paste;
  454.     DoOr;
  455.     PlotTop:=PlotTop+PlotHeight-1;
  456.     SelectPic(ImageWindow);
  457.     angle:=angle+delta;
  458.   end;
  459.   RestoreState;
  460. end;
  461.  
  462.  
  463. macro 'Circular Profile Plot [C]';
  464. var
  465.   radius,pi,angle,dx,dy,delta:real;
  466.   x1,y1,x2,y2:real;
  467.   npoints,i,value,LineWidth,x,y,px:integer;
  468. begin
  469.   GetLine(x1,y1,x2,y2,LineWidth)
  470.   if x1<0 then begin
  471.     PutMessage('Please select a point by clicking with the line tool.');
  472.     exit;
  473.   end;
  474.   x:=x1+(x2-x1)/2;
  475.   y:=y1+(y2-y1)/2;
  476.   radius:=sqrt(sqr(x2-x1)+sqr(y2-y1))/2;
  477.   if radius<3 then begin
  478.     PutMessage('The line selection must be longer than 5 pixels.');
  479.     exit;
  480.   end;
  481.   npoints:=radius*2;
  482.   pi:=3.14159;
  483.   delta:=2.0*pi/npoints;
  484.   angle:=0.0;
  485.   px:=0;
  486.   for i:=1 TO npoints do begin
  487.     dx:=round(radius*cos(angle));
  488.     dy:=round(radius*sin(angle));
  489.     value:=GetPixel(x+dx,y+dy);
  490.     PutPixel(x+dx,y+dy,255);
  491.     PutPixel(px,0,value);
  492.     px:=px+1;
  493.     angle:=angle+delta;
  494.   end;
  495.   MakeLineRoi(0,0,npoints,0);
  496.   PlotProfile;
  497.   KillRoi;
  498. end;
  499.  
  500.  
  501. macro 'Compute Spatial Scale';
  502. var
  503.   scale:real;
  504. begin
  505.   MakeLineRoi(0,0,100,0);
  506.   Measure;
  507.   KillRoi;
  508.   Scale:=100/rLength[rCount]);
  509.   if scale=1
  510.     then PutMessage('Image is not spatially calibrated')
  511.     else PutMessage('Scale=',scale:1:4,' pixels/unit');
  512. end;
  513.  
  514.  
  515. macro 'Store Break in Results [S]';
  516. {Stores a row of zeros in the results table.}
  517. begin
  518.   Measure;
  519.   rArea[rCount]:=0;
  520.   rMean[rCount]:=0;
  521.   rStdDev[rCount]:=0;
  522.   rX[rCount]:=0;
  523.   rY[rCount]:=0;
  524.   rLength[rCount]:=0;
  525.   rMajor[rCount]:=0;
  526.   rMinor[rCount]:=0;
  527.   rAngle[rCount]:=0;
  528.   UpdateResults;
  529. end;
  530.  
  531.  
  532. macro 'Measure both Raw and Calibrated';
  533. {
  534. This macro is a variation of the Measure command that displays the number
  535. of pixels in User1 and uncalibrated(raw) mean density in User2. It takes
  536. advantage of the fact that GetResults always returns uncalibrated values.
  537. }
  538. var
  539.   nPixels,mean,mode,min,max:real;
  540. begin
  541.   SetUser1Label('Pixels');
  542.   SetUser2Labe2('Raw Mean');
  543.   Measure;
  544.   GetResults(nPixels,mean,mode,min,max);
  545.   rUser1[rCount]:=nPixels;
  546.   rUser2[rCount]:=mean;
  547.   UpdateResults;
  548. end;
  549.  
  550.  
  551.  
  552.  
  553.  
  554.  
  555.  
  556.  
  557.